import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import dts from "vite-plugin-dts";
import { resolve } from "path";
import vueJsx from "@vitejs/plugin-vue-jsx";

export default defineConfig({
  resolve: {
    alias: {
      "~/": `${resolve(__dirname, "src")}/`,
      "@nf-ui": `${resolve(__dirname)}/packages`,
    },
  },
  build: {
    // target: 'modules',
    // //打包文件目录
    outDir: "nf-ui",
    //压缩
    // minify: true,
    //css分离
    // cssCodeSplit: true,
    rollupOptions: {
      //忽略打包vue文件
      external: [
        "vue",
        "echarts",
        "lodash-es",
        "echarts-wordcloud",
        "flag-icons",
        "@vueuse/core",
      ],
      input: [resolve(__dirname, "packages/index.ts")],
      output: [
        {
          //打包格式
          format: "es",
          //打包后文件名
          entryFileNames: "[name].mjs",
          //让打包目录和我们目录对应
          preserveModules: true,
          exports: "named",
          //配置打包根目录
          preserveModulesRoot: "src",
          dir: resolve(__dirname, "nf-ui/es"),
        },
        // {
        //   //打包格式
        //   format: "cjs",
        //   //打包后文件名
        //   entryFileNames: "[name].js",
        //   //让打包目录和我们目录对应
        //   preserveModules: true,
        //   exports: "named",
        //   preserveModulesRoot: "src",
        //   //配置打包根目录
        //   dir: resolve(__dirname, "nf-ui/lib"),
        // },
      ],
    },
    lib: {
      entry: resolve(__dirname, "packages/index.ts"),
      name: "nf-ui",
    },
  },
  plugins: [
    vue(),
    dts({
      include: [resolve(__dirname, "packages")],
      exclude: [resolve(__dirname, "packages/theme-default/**")],
      outDir: [resolve(__dirname, "nf-ui/es")],
      tsconfigPath: resolve(__dirname, "tsconfig.json"),
      clearPureImport: false,
    }),
    // dts({
    //   include: ["./packages"],
    //   exclude: ["./packages/theme-default/**"],
    //   outDir: ["./nf-ui/lib"],
    //   tsconfigPath: "./tsconfig.json",
    // }),
    vueJsx(),
  ],
});
